package String;

public class _71_SimplifyPath {
    public String simplifyPath(String path) {
        String res = "";
        String[] parameters = path.split("/");
        int skip = 0;
        for (int i = parameters.length-1; i >= 0; i--) {
            String parameter = parameters[i];
            if (parameter.equals(".") || parameter.equals("")) {
                continue;
            } else if (parameter.equals("..")) {
                skip++;
            } else if (skip>0) {
                skip--;
            } else {
                res = "/" + parameter + res;
            }
        }
        return res==""?"/":res;
    }
}
